<?php
	$funeralhome_id = $this->VAS_fh_id;
	$branch_number = $this->branch_number;
	
	// compute quick stats and just put them in a div list for now
	$qs = $this->quickStats;
	if(isset($qs['module_times']))
	{
		$str1 = sprintf("TOTAL Number of cases: %d", $qs['num_cases']);
		$str2 = sprintf("Average time per case: %.1f seconds", $qs['time_per_case']);
		$overall = "<div>$str1<br>$str2</div>";
		
		$per_module = "<br>Average time per module:";

		foreach($qs['module_times'] as $module_name=>$tuple)
		{
			$per_module .= "<div>";
			$per_module .= sprintf("%s: %.1f seconds", $module_name, $tuple['Average']);
			$per_module .= "</div>";
		}
		$quick_stats = "$overall $per_module";
	}
	else
	{
		$quick_stats = "";
	}
	
	// $this->bstats and $this->brevs
	$branch_timing_stats = sprintf("<br>Total Cases: %d<br>Shortest Time: %.1f<br>Longest Time: %.1f<br>Average Time: %.1f", 
		$this->bstats['num_cases'], $this->bstats['min_casetime'], $this->bstats['max_casetime'], $this->bstats['avg_casetime'] );
	$branch_revenue_stats = sprintf("<br>Total Cases: %d<br>Lowest Revenue: \$%.02f<br>Highest Revenue: \$%.02f<br>Total Revenue: \$%.02f<br>Average Revenue: \$%.02f", 
		$this->brevs['num_cases'], 
		$this->brevs['min_revenue'], 
		$this->brevs['max_revenue'], 
		$this->brevs['sum_revenue'], 
		$this->brevs['avg_revenue'] );
		
	$region_timing_stats = sprintf("<br>Total Cases: %d<br>Shortest Time: %.1f<br>Longest Time: %.1f<br>Average Time: %.1f", 
		$this->rstats['num_cases'], $this->rstats['min_casetime'], $this->rstats['max_casetime'], $this->rstats['avg_casetime'] );
	$region_revenue_stats = sprintf("<br>Total Cases: %d<br>Lowest Revenue: \$%.02f<br>Highest Revenue: \$%.02f<br>Total Revenue: \$%.02f<br>Average Revenue: \$%.02f", 
		$this->rrevs['num_cases'], 
		$this->rrevs['min_revenue'], 
		$this->rrevs['max_revenue'], 
		$this->rrevs['sum_revenue'], 
		$this->rrevs['avg_revenue'] );

	$keystone_timing_stats = sprintf("<br>Total Cases: %d<br>Shortest Time: %.1f<br>Longest Time: %.1f<br>Average Time: %.1f", 
		$this->cstats['num_cases'], $this->cstats['min_casetime'], $this->cstats['max_casetime'], $this->cstats['avg_casetime'] );
	$keystone_revenue_stats = sprintf("<br>Total Cases: %d<br>Lowest Revenue: \$%.02f<br>Highest Revenue: \$%.02f<br>Total Revenue: \$%.02f<br>Average Revenue: \$%.02f", 
		$this->crevs['num_cases'], 
		$this->crevs['min_revenue'], 
		$this->crevs['max_revenue'], 
		$this->crevs['sum_revenue'], 
		$this->crevs['avg_revenue'] );
		
 ?>
<ul class="basictab">
<li class="selected"><a href="/index/funeralhome/branch_number/<?php echo $branch_number?>">Profile</a></li>
<li><a href="/index/funeralhomemerchandise/branch_number/<?php echo $branch_number?>">Priority Merchandise</a></li>
</ul>
<div class="basictabdiv">
<?php
	$fhPicName = $this->funeral_home['photo_image'];
	$fhLogoName = $this->funeral_home['logo_image'];
	$fhPicPath = FH_ART_BASE."/".$fhPicName;

	$fhLogoPath = FH_ART_BASE."/".$fhLogoName;
	$fhProfileForm = new FHProfileForm(
		array('funeral_home'=>$this->funeral_home, 
		'VASfh_id'=>$this->VAS_fh_id,
		'branch_number'=>$branch_number,
		'fh_picture_path'=>$fhPicPath,
		'fh_logo_path'=>$fhLogoPath,
		'quick_stats'=>$quick_stats,
		'branch_timing'=>$branch_timing_stats,
		'branch_revenue'=>$branch_revenue_stats,
		'region_timing'=>$region_timing_stats,
		'region_revenue'=>$region_revenue_stats,
		'keystone_timing'=>$keystone_timing_stats,
		'keystone_revenue'=>$keystone_revenue_stats,
		'num_open_cases'=>$this->numOpenCases
		 ));

	$fhProfileForm->setAction( '/index/funeralhome');
	
	$fhProfileForm->isValid( $this->funeral_home );
	$fhProfileForm->populate( $this->funeral_home );
	
	$rendered_form = $fhProfileForm->render_with_template("funeralhomeprofile.xhtml");
	echo $rendered_form;
	
	//echo $rendered_form;//{NUMOPENCASES}
	
 ?>
</div> 
